﻿using System;
using System.IO;
using System.Net;

namespace Demo
{
    class Program
    {
        static void Main(string[] args)
        {

            string url = @"https://www.cnblogs.com/images/logo_small.gif";
            //获取网站当前根目录
            string sWebRootFolder = "d://data";
            //保存图片路径
            var savePath = string.Format("\\Uploads\\{0}\\{1}\\{2}\\", DateTime.Now.Year, DateTime.Now.Month.ToString("D2"), DateTime.Now.Day.ToString("D2"));
            //文件名
            string filename = System.IO.Path.GetFileName(url);
            //扩展名
            string extension = System.IO.Path.GetExtension(url);
            savePath = sWebRootFolder + savePath;
            //无夹创建
            if (!Directory.Exists(savePath))
            {
                Directory.CreateDirectory(savePath);
            }
            WebClient mywebclient = new WebClient();
            //下载文件
            mywebclient.DownloadFile(url, savePath + filename);


            Console.WriteLine("Hello World!");
        }

    }
}
